home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / tool_inc.zip / TOP.INC < prev    next >
Text File  |  1989-03-01  |  5KB  |  184 lines

  1.  
  2. (*
  3.  * Copyright 1987, 1989 Samuel H. Smith;  All rights reserved
  4.  *
  5.  * This is a component of the ProDoor System.
  6.  * Do not distribute modified versions without my permission.
  7.  * Do not remove or alter this notice or any other copyright notice.
  8.  * If you use this in your own program you must distribute source code.
  9.  * Do not use any of this in a commercial product.
  10.  *
  11.  *)
  12.  
  13. (*
  14.  * top - utility library for simple "pull-down" windows
  15.  *        uses functions in popup.inc (3-1-89)
  16.  *
  17.  *)
  18.  
  19. procedure select_pulled(pullno:   integer;
  20.                         var sel:  char);
  21.    (* select and execute a pulldown window *)
  22. var
  23.    save: window_save_rec;
  24. begin
  25.    save_window(save);
  26.    window(1,1,80,25);
  27.    pulldown(wherex-0,wherey+1,pullno,pull_table[pullno],sel);
  28.    restore_window(save);
  29. end;
  30.  
  31.  
  32. procedure top_menu(topx,topy:   integer;
  33.                    var top:     pulldown_rec);
  34.    {top level pulldown window processor; display the top level window
  35.     and process pulldowns related to it}
  36.  
  37.    procedure display_entry(entry: integer);
  38.    var
  39.       i,x: integer;
  40.    begin
  41.       x := topx+1;
  42.       for i := 1 to entry-1 do
  43.          x := x + length(top.line[i].title) + 3;
  44.  
  45.       gotoxy(x,topy);
  46.       disp(' '+top.line[entry].title+' ');
  47.       gotoxy(x+1,topy);
  48.    end;
  49.  
  50.    procedure display_top;
  51.       {open a pulldown window at top-left x and y location.
  52.        use the top record to describe the options}
  53.    var
  54.       i,
  55.       j:                  integer;
  56.       active:             integer;
  57.    begin
  58.  
  59.    (* count active entries *)
  60.       active := 0;
  61.       for i := 1 to max_pulldown do
  62.          with top.line[i] do
  63.             if action <> unused_entry then
  64.                inc(active);
  65.  
  66.  
  67.    (* display the border *)
  68.       window(1,1,80,25);
  69.       setcolor(top.border_fg, top.border_bg);
  70.  
  71.       if topy > 1 then
  72.       begin
  73.          gotoxy(topx,topy-1);
  74.          disp('┌');
  75.          for i := 1 to active-1 do
  76.             disp(make_string('─',length(top.line[i].title)+2) + '┬');
  77.          disp(make_string('─',length(top.line[active].title)+2) + '┐');
  78.       end;
  79.  
  80.       gotoxy(topx,topy);
  81.       disp('│');
  82.       for i := 1 to active do
  83.          disp(make_string(' ',length(top.line[i].title)+2) + '│');
  84.  
  85.       gotoxy(topx,topy+1);
  86.       disp('└');
  87.       for i := 1 to active-1 do
  88.          disp(make_string('─',length(top.line[i].title)+2) + '┴');
  89.       disp(make_string('─',length(top.line[active].title)+2) + '┘');
  90.  
  91.    (* print option descriptions *)
  92.       setcolor(top.text_fg, top.text_bg);
  93.       for i := 1 to active do
  94.          display_entry(i);
  95.    end;
  96.  
  97.  
  98.    procedure pick_top;
  99.       {select an entry from a pulldown window.
  100.        the pulldown must already be on the display}
  101.    var
  102.       pulled:  boolean;
  103.       found:   integer;
  104.       entry:   integer;
  105.       i:       integer;
  106.       sel:     char;
  107.  
  108.       procedure moveby(by: integer);
  109.       begin
  110.          repeat
  111.             entry := entry + by;
  112.             if entry > max_pulldown then
  113.                entry := 1
  114.             else if entry < 1 then
  115.                entry := max_pulldown;
  116.          until top.line[entry].action <> unused_entry;
  117.       end;
  118.  
  119.       procedure select_top;
  120.       begin
  121.          sel := upcase(getkey);
  122.       end;
  123.  
  124.  
  125.    begin
  126.       (* pick the initial selection *)
  127.       pulled := false;
  128.       entry := 0;
  129.       moveby(1);
  130.  
  131.       (* process top level options *)
  132.       repeat
  133.          setcolor(top.select_fg, top.select_bg);
  134.          display_entry(entry);
  135.  
  136.          if pulled then
  137.             select_pulled(top.line[entry].action,sel)
  138.          else
  139.             select_top;
  140.  
  141.          setcolor(top.text_fg, top.text_bg);
  142.          display_entry(entry);
  143.  
  144.          case sel of
  145.             LEFT:      moveby(-1);
  146.             RIGHT:     moveby(1);
  147.  
  148.             DOWN,
  149.             NEWLINE:   pulled := true;
  150.             ESC:       pulled := false;
  151.  
  152.             quit_sel:  exit;
  153.  
  154.             else
  155.             begin
  156.                (* test for capitalized letters *)
  157.                found := 0;
  158.                for i := max_pulldown downto 1 do
  159.                with top.line[i] do
  160.                   if pos(sel, title) > 0 then
  161.                   begin
  162.                      entry := i;
  163.                      found := -1;
  164.                   end;
  165.  
  166.                if found = 0 then
  167.                begin
  168.                   if pulldown_key(0,entry,sel) then
  169.                      exit;
  170.                end;
  171.             end;
  172.          end;
  173.  
  174.       until true=false;
  175.    end;
  176.  
  177.  
  178. begin {pulldown}
  179.    display_top;
  180.    pick_top;
  181.    window(1,1,80,25);
  182. end;
  183.  
  184.